<?php

  require_once "JooS/Server/Controller.php";

  abstract class JooS_Server_Controller_File extends JooS_Server_Controller {
    abstract protected function getFileContent($fileName);

    public function getResponse() {
      $request = JooS_Server::getInstance()->getRequest();
      $uri = trim($request->getResourceUri(), "/");

      $parts = explode("/", $uri);

      $fileFolder = "/" . $parts[0] . "/";
      unset($parts[0]);
      $fileName = implode("/", $parts);

      $fileContent = $this->getFileContent($fileName);

      $responseCode = $fileContent->getErrorCode() ? $fileContent->getErrorCode() : 200;
      $responseBody = $fileContent->getCopyrights() . $fileContent->getValue();
      $responseHeaders = array(
        "Content-Type" => $fileContent->getContentType() . "; charset=" . ini_get("default_charset"), 
        "Content-Length" => strlen($responseBody)
      );

/**
 *
 * @todo save
 *
 **/

      require_once "JooS/Server/Response.php";
      return new JooS_Server_Response($responseCode, $responseHeaders, $responseBody);
    }

  }

?>